/**
 * Copyright (c) 2011-9-23 WKM and/or its affiliates. 
 * Use is subject to license terms.
 * All rights reserved.
 */
package org.wkm.task.file;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wkm.util.Configuration;
import org.wkm.util.Home;

/**
 * The class note
 * @version 1.0 2011-12-13
 * @author WUKUNMENG
 */
public class TaskWriter {
	
	private static Logger logger = LoggerFactory.getLogger(TaskReader.class);
	
	public void createTask(String name,String content){
		File f = new File(Home.getPath(Configuration.TASK_CONFIG));
		File file = new File(f,name + Configuration.TASK_CONFIG_SUF);
		if(file.exists()){
			file.delete();
		}
		try {
			file.createNewFile();
			FileWriter fw = new FileWriter(file,false);
			fw.write(content);
			fw.close();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		
	}
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		StringBuffer sb = new StringBuffer();
		sb.append("test.w=w" + System.getProperty("line.separator"));
		sb.append("test.q=q" + System.getProperty("line.separator"));
		sb.append("test.e=e");
		new TaskWriter().createTask("test1", sb.toString());
		
		TaskReader tr = TaskReader.getInstance();
		Properties p = tr.getProperties("test1");
		System.out.println(p.get("test.w"));
		System.out.println(p.get("test.q"));
		System.out.println(p.get("test.e"));
		System.out.println(p);
	}
}
